From de72df4032c0e0dbc8c08d4c0b4424f42ed3b8aa Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 16 Jan 2007 01:45:51 +0000 Subject: [PATCH] * (bug 3000) Fall back to SCRIPT_NAME plus QUERY_STRING when REQUEST_URI is not available, as on IIS with PHP-CGI --- RELEASE-NOTES | 2 ++ includes/Exception.php | 3 ++- includes/GlobalFunctions.php | 2 +- includes/Skin.php | 7 ------- includes/WebRequest.php | 15 ++++++++++++++- includes/Wiki.php | 5 ++--- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2ae678775f..b25915ec93 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -76,6 +76,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 8629) Document $wgFilterCallback * (bug 1000) Clarify warning about memory_limit in installer * Suppress PHP warning about set_time_limit in installer when safe mode is on +* (bug 3000) Fall back to SCRIPT_NAME plus QUERY_STRING when REQUEST_URI is + not available, as on IIS with PHP-CGI == Languages updated == diff --git a/includes/Exception.php b/includes/Exception.php index ac9c8a2151..ad7ec14a93 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -54,10 +54,11 @@ class MWException extends Exception } function getLogMessage() { + global $wgRequest; $file = $this->getFile(); $line = $this->getLine(); $message = $this->getMessage(); - return "{$_SERVER['REQUEST_URI']} Exception from line $line of $file: $message"; + return $wgRequest->getRequestURL() . " Exception from line $line of $file: $message"; } function reportHTML() { diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index c52c346edc..777c02c417 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -230,7 +230,7 @@ function wfLogProfilingData() { $forward .= ' anon'; $log = sprintf( "%s\t%04.3f\t%s\n", gmdate( 'YmdHis' ), $elapsed, - urldecode( $_SERVER['REQUEST_URI'] . $forward ) ); + urldecode( $wgRequest->getRequestURL() . $forward ) ); if ( '' != $wgDebugLogFile && ( $wgRequest->getVal('action') != 'raw' || $wgDebugRawPage ) ) { error_log( $log . $prof, 3, $wgDebugLogFile ); } diff --git a/includes/Skin.php b/includes/Skin.php index e7f6df8d56..05689285dc 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -782,13 +782,6 @@ END; function printableLink() { global $wgOut, $wgFeedClasses, $wgRequest; - $baseurl = $_SERVER['REQUEST_URI']; - if( strpos( '?', $baseurl ) == false ) { - $baseurl .= '?'; - } else { - $baseurl .= '&'; - } - $baseurl = htmlspecialchars( $baseurl ); $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' ); $s = "" . wfMsg( 'printableversion' ) . ''; diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 353369547e..7648b75f1c 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -314,7 +314,20 @@ class WebRequest { * @return string */ function getRequestURL() { - $base = $_SERVER['REQUEST_URI']; + if( isset( $_SERVER['REQUEST_URI'] ) ) { + $base = $_SERVER['REQUEST_URI']; + } elseif( isset( $_SERVER['SCRIPT_NAME'] ) ) { + // Probably IIS; doesn't set REQUEST_URI + $base = $_SERVER['SCRIPT_NAME']; + if( isset( $_SERVER['QUERY_STRING'] ) && $_SERVER['QUERY_STRING'] != '' ) { + $base .= '?' . $_SERVER['QUERY_STRING']; + } + } else { + // This shouldn't happen! + throw new MWException( "Web server doesn't provide either " . + "REQUEST_URI or SCRIPT_NAME. Report details of your " . + "web server configuration to http://bugzilla.wikimedia.org/" ); + } if( $base{0} == '/' ) { return $base; } else { diff --git a/includes/Wiki.php b/includes/Wiki.php index 4fa421a69a..06ae8cfeeb 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -118,7 +118,7 @@ class MediaWiki { * Initialize the object to be known as $wgArticle for special cases */ function initializeSpecialCases ( &$title, &$output, $request ) { - + global $wgRequest; wfProfileIn( 'MediaWiki::initializeSpecialCases' ); $search = $this->getVal('Search'); @@ -151,8 +151,7 @@ class MediaWiki { $targetUrl = $title->getFullURL(); // Redirect to canonical url, make it a 301 to allow caching global $wgServer, $wgUsePathInfo; - if( isset( $_SERVER['REQUEST_URI'] ) && - $targetUrl == $wgServer . $_SERVER['REQUEST_URI'] ) { + if( $targetUrl == $wgRequest->getFullRequestURL() ) { $message = "Redirect loop detected!\n\n" . "This means the wiki got confused about what page was " . "requested; this sometimes happens when moving a wiki " . -- 2.20.1